# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
from qfluentwidgets import ThemeColor, Theme, isDarkTheme, IconWidget, BodyLabel, setFont

from common import SingleIcon
from .right_widget import RightWidget


class LoginInterface(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.horizontalLayout = QHBoxLayout(self)
        self.leftWidget = QWidget(self)
        self.rightWidget = QWidget(self)
        self.leftLayout = QVBoxLayout(self.leftWidget)
        self.rightLayout = QVBoxLayout(self.rightWidget)

        self.leftIconWidget = IconWidget(SingleIcon.QS_LOGO, self.leftWidget)
        self.titleLabel = BodyLabel("青书学堂在线教育综合平台", self.leftWidget)
        self.contentLabel = BodyLabel(" - 成人学历教育一站式解决方案", self.rightWidget)
        self.contentLabel_2 = BodyLabel(" - 高职高专教育一站式解决方案", self.rightWidget)
        self.contentLabel_3 = BodyLabel(" - 非学历培训教育一站式解决方案", self.rightWidget)
        self.leftBottomIconWidget = IconWidget(SingleIcon.AUTH_LEFT_IMG, self.leftWidget)

        self.rightCardWidget = RightWidget(self.rightWidget)

        self.__initWidgets()

    def __initWidgets(self):
        self.setWindowTitle("登录")
        self.updateBackground()

        setFont(self.titleLabel, 33)
        self.titleLabel.setTextColor(QColor('#ffffff'), QColor('#ffffff'))
        self.contentLabel.setTextColor(QColor('#ffffff'), QColor('#ffffff'))
        self.contentLabel_2.setTextColor(QColor('#ffffff'), QColor('#ffffff'))
        self.contentLabel_3.setTextColor(QColor('#ffffff'), QColor('#ffffff'))

        self.leftIconWidget.setFixedSize(178, 100)
        self.leftBottomIconWidget.setFixedSize(320, 200)

        self.__initLayout()

    def __initLayout(self):
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.addWidget(self.leftWidget, 1)
        self.horizontalLayout.addWidget(self.rightWidget, 1)
        self.horizontalLayout.setStretch(0, 1)
        self.horizontalLayout.setStretch(1, 2)

        self.leftLayout.setAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignHCenter)
        self.leftLayout.setSpacing(20)
        self.leftLayout.setContentsMargins(50, 50, 50, 50)
        self.leftLayout.addWidget(self.leftIconWidget)
        self.leftLayout.addWidget(self.titleLabel)
        self.leftLayout.addWidget(self.contentLabel)
        self.leftLayout.addWidget(self.contentLabel_2)
        self.leftLayout.addWidget(self.contentLabel_3)
        self.leftLayout.addWidget(self.leftBottomIconWidget)

        self.rightLayout.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.rightLayout.setContentsMargins(50, 50, 50, 50)
        self.rightLayout.addWidget(self.rightCardWidget, 1, Qt.AlignmentFlag.AlignCenter)

    def updateBackground(self, theme: Theme = None):
        color = ThemeColor.DARK_2.name() if isDarkTheme() else ThemeColor.LIGHT_2.name()
        self.leftWidget.setStyleSheet(f'QWidget {{background-color: {color};}}')
